package com.ztgf.shopping.api.client.template;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.template.IContractTempletService;
import com.ztgf.shopping.models.bo.template.ContractTempletBO;
import com.ztgf.shopping.models.dto.template.ContractTempletDTO;

/**
 * 合同模版控制器
 *
 * @author YUE
 * @Date 2020-05-28 16:00:45
 */

@RestController
@RequestMapping("/api/contractTemplet")
@Slf4j
@Api(value = "ContractTempletApiController",tags = "合同模版Api接口")
public class ContractTempletApiController {

    @DubboReference
    private IContractTempletService contractTempletService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ContractTempletDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ContractTempletDTO dto = contractTempletService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "合同模版列表",notes = "合同模版列表")
    @PostMapping("/queryPageList")
    public Result<Page<ContractTempletDTO>> queryPageList(ContractTempletBO bo){
       Wrapper<ContractTempletDTO> wrapper = new EntityWrapper<>();
                if (bo.getStatus() != null){
                    wrapper.eq("status", bo.getStatus());
                }
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<ContractTempletDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = contractTempletService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
